package com.demo.springboot.controller;

import com.demo.springboot.dao.UserDao;
import com.demo.springboot.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * @ClassName LoginController
 * @Description TODO
 * @Author tianqinglong
 * @Date 19:07 2022/7/14
 * @Version 1.0
 **/
@Controller
public class RegisterController {
    @Autowired
    private UserDao userDao;


    @RequestMapping("toRegister")
    public String toRegister(){
        return "register";
    }

    @RequestMapping("register")
    @ResponseBody
    public String register( User user){
        ArrayList<User> list = userDao.getList();
        for (int i = 0; i < list.size(); i++) {
            if(user.equals(list.get(i))){
                return "注册失败";
            }
        }
         list.add(user);
        System.out.println(list);
        return "注册成功";


    }
}
